package org.example;

import java.io.*;

public class SessionState implements Serializable {
    private String userId;
    private String data;

    public SessionState(String userId, String data) {
        this.userId = userId;
        this.data = data;
    }

//序列化方法
    public byte[] serialize() throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        return bos.toByteArray();
    }

//反序列化方法
    public static SessionState deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);
        return (SessionState) ois.readObject();
    }
}
